/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package intmag;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Den
 */
public class ShopPanel extends JPanel {

    private Bascket bascket;
    private JLabel id;
    private JLabel description;
    private JLabel icon;
    private JLabel price;
    
    private Goods goods;
    
    private JButton buyButton;
    
    public ShopPanel() {
        bascket = new Bascket();
        id = new JLabel();
        description = new JLabel();
        icon = new JLabel();
        price = new JLabel();
        init();
        
    }

    private void init() {
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        JButton buyButton=new JButton("text");
        buyButton.setAction(new AbstractAction("Buy") {

            @Override
            public void actionPerformed(ActionEvent e) {
              bascket.inGoodsCountAndChangeLabelText("Buy now");
            }
        });
        
        Box bascketBox = Box.createHorizontalBox();
        bascketBox.add(Box.createHorizontalGlue());
        bascketBox.add(bascket);

        add(bascketBox);

        Box infoBox = Box.createHorizontalBox();
        Box iconBox = Box.createHorizontalBox();
        iconBox.add(icon);

        Box textInfoBox = Box.createVerticalBox();
        textInfoBox.add(id);
        textInfoBox.add(icon);

        infoBox.add(textInfoBox);
        infoBox.add(iconBox);
        add(infoBox);

    }

    private void fillForm(Goods goods) {
        id.setText(String.valueOf(goods.getId()));
        description.setText(goods.getDescriptoin());
        price.setText(String.valueOf(goods.getPrice()));
        icon.setIcon(goods.getIcon());

    }

    public void setGoods(Goods goods) {
        this.goods = goods;
        fillForm(goods);
    }

    public Goods getGoods() {
        return goods;
    }

    
    
    
}
